<template>
  <div class="h100 sysLogPage">
    <div class="sysLogSearch table-page-search-wrapper">
      <sysAnnounce-search @handleAddEdit="handleAddEdit" @clickbtn="handleClickSearchBtn"></sysAnnounce-search>
    </div>
    <div class="sysLogMain">
      <sysAnnounce-table-list :userData="userData" @handleAddEdit="handleAddEdit" ref="sysAnnounceMainComp"></sysAnnounce-table-list>
    </div>
    <new-edit-announce :userData="userData" :roleData="roleData" @clickbtn="handleClickSearchBtn" ref="modalForm"></new-edit-announce>
  </div>
</template>
<script>
import SysAnnounceSearch from './components/SysAnnounceSearch.vue'
import { minxinDrawerUse } from '@/utils/mixin'
import SysAnnounceTableList from './components/SysAnnounceTableList.vue'
import NewEditAnnounce from './components/NewEditAnnounce.vue'
import sysAnnounceApi from '@/api/modules/system/announce'
import { mapState, mapGetters,mapMutations } from 'vuex'
export default {
   mixins: [minxinDrawerUse],
  components: {
    SysAnnounceSearch,
    SysAnnounceTableList,
    NewEditAnnounce
  },
  computed: {
    ...mapState({
      queryParams: (state) => state.sysAnnounce.queryParams
    }),
  },
  data () {
    return {
       userData:[],
       roleData:[],
    }
  },
  created () {
    this.getUserData()
    this.getRoleData()
  },
  methods: {
    ...mapMutations(['setInstantUpdateTime']),
      // 获取所有用户数据
    getUserData () {
      let params={
        pageNo: 1,
        pageSize: 120
      }
      sysAnnounceApi.getUserPageData(params).then(res => {
        this.userData = res.data
      }).finally(() => {
      })
    },
     // 获取所有角色数据
    getRoleData () {
      sysAnnounceApi
        .getRoleAllData()
        .then((res) => {
          this.roleData = res.data
        })
        .finally(() => {})
    },
    handleAddEdit(recordData = {}) {
      this.$refs.modalForm.show(recordData)
    },
    handleClickSearchBtn (data) {
      if (this[data.type]) {
        this[data.type](data)
      }
    },
    searchData (isToFirstPage) {
      this.$refs.sysAnnounceMainComp.refreshData(isToFirstPage)
    },
   
  },
  beforeDestroy () {
    this.$store.commit('resetSysAnnounceQueryParams')
  }
}
</script>
<style lang="less" scoped>
@import url('./style/list.less');
</style>
